// 获取节点函数
function gitEle(ele) {
    return document.querySelector(ele)
}
function gitEleAll(ele) {
    return document.querySelectorAll(ele)
}
//模态框函数··················································································································
function displayMask() {
    let apple = gitEleAll('.main ul h4')

    apple.forEach(function (v) {
        v.addEventListener('click', function () {

            gitEle('.blanket').style.display = 'block'
        })
    })
    gitEle('.blanket').addEventListener('click', function () {

        gitEle('.blanket').style.display = 'none'
    })
    gitEle('form').addEventListener('click', function (e) {
        e.stopPropagation()
    })

    //获取点击事件的标签
    let switcher = gitEleAll('.lon-ins div')
    // 获取显示隐藏的div
    let box1 = gitEleAll('.Login-box')
    //遍历事件源
    switcher.forEach(function (itme, i) {
        // 遍历数组清空类名
        itme.addEventListener('click', function () {
            switcher.forEach(function (v, index) {
                v.className = '';
                v.className = 'fl font20';
                box1[index].style.display = "none"

            })
            //添加样式类名
            this.className = 'on active fl font20';


            box1[i].style.display = "block"
        })
    })

}
// ··················································································································
// apl页面渲染
// let pageNum = 0;
//     let currentPage = 5;
function subentry(element, pageNum, currentPage, listDataArr) {


    gitEle(element).innerHTML = ''
    listDataArr.slice(pageNum, currentPage).forEach(function (v) {

        gitEle(element).innerHTML +=
            `<li>
            <h1 class="${v.isSpecial ? 'on' : ''}">企业专业</h1>
            <img src="./images/${v.img}" alt="">
            <h2 class="mb10">${v.name}</h2>
            <h3 class="${v.price === '免费' ? 'green' : 'red'}">${v.price}</h3>
            <h4>申请数据</h4>

        </li>`
    })
}
// api点击图片跳转函数
function imgHref() {
    let imgs = gitEleAll('.main ul img')
    imgs.forEach(function (v) {
        v.addEventListener('click', function () {
            window.location.href = 'api-paging.html'
        })
    })
}
// 用户名函数
function userName(val) {
    return /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/.test(val)
}
// 密码函数
function pwd1(val) {
    return /^[a-zA-Z]\w{5,17}$/.test(val)
}
// 菜单函数调用，及点击与隐藏
function menu(element1, style1, element2, style2) {
    let span2 = gitEleAll(element1)
    let content = gitEleAll(element2)
    span2.forEach(function (v, i) {
        v.addEventListener('click', function () {
            span2.forEach(function (v, i) {
                v.classList.remove(style1)
                if (content.length != 0) {
                    content[i].classList.remove(style2)
                }
            })
            v.classList.add(style1)
            if (content.length != 0) {
                content[i].classList.add(style2)
            }

        })


    })
}